import logging,threading
from web_element import main
logger = logging.getLogger("RedBook")
logger.setLevel(logging.DEBUG)
# 建立一个filehandler来把日志记录在文件里，级别为debug以上
fh = logging.FileHandler("spam.log",encoding="utf-8")
fh.setLevel(logging.DEBUG)
# 建立一个streamhandler来把日志打在CMD窗口上，级别为error以上
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG) #INFO
# 设置日志格式
# threadName = threading.current_thread().name
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(threadName)s : %(message)s")
ch.setFormatter(formatter)
fh.setFormatter(formatter)
#将相应的handler添加在logger对象中
logger.addHandler(ch)
logger.addHandler(fh)


def main():
	# 开始打日志
	logger.debug("debug message")
	logger.info("info message")
	logger.warn("warn message")
	logger.error("error message")
	logger.critical("critical message")

if __name__ == "__main__":
    main()